from selenium.webdriver.common.by import By
from pages.base_page import Page
from selenium.webdriver.support.wait import WebDriverWait


class ReportingManualInvitationPage(Page):
    ele_title = (By.XPATH, u"//h3[text()='Manual Invitation']")
    ele_by_time = (By.XPATH, u"//span[text()='By Time']")
    ele_by_agent = (By.XPATH, u"//span[text()='By Agent']")

    ele_by_time_form = (By.XPATH, u'//canvas')
    ele_by_agent_form = (By.XPATH, u'//div[text()="Sent"]')

    ele_chat_with_us_button = (By.XPATH, u'//span[text()="Chat with us"]')

    def __init__(self, driver, url, site_id):
        Page.__init__(self, driver, url)
        self.site_id = site_id
        self.url = url

    def check_manual_invitation_page_when_has_feature(self):
        self.find_element(*self.ele_title).is_enabled()
        self.find_element(*self.ele_by_time).is_enabled()
        self.find_element(*self.ele_by_agent).is_enabled()
        self.find_element(*self.ele_by_time_form).is_enabled()

        self.click(self.ele_by_agent)
        WebDriverWait(self.driver, 10).until(lambda x: x.find_element_by_xpath(u'//div[text()="Sent"]'))
        self.find_element(*self.ele_by_agent_form).is_enabled()

    def check_manual_invitation_page_when_no_feature(self):
        self.find_element(*self.ele_title).is_enabled()
        self.find_element(*self.ele_chat_with_us_button).is_enabled()
